package com.gzz.orchid.common.core.tuple;

import com.gzz.orchid.common.core.exception.ValidationException;
import com.gzz.orchid.common.core.util.I18nUtil;
import lombok.Value;

import java.util.Objects;
import java.util.regex.Pattern;

/**
 * 手机号
 *
 * @author higmd
 */
@Value
public class MobileNumber {
    String value;
    // 构造函数
    public MobileNumber(String value) {
        if (Objects.isNull(value)) {
            throw new ValidationException(I18nUtil.ofMessage("number不能为空"));
        } else if (!Pattern.matches("(1[2-9])\\d{9}$", value)) {
            throw new ValidationException(I18nUtil.ofMessage("不是有效手机号"));
        }
        this.value = value;
    }
}
